package hos.demo

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import hos.demo.ui.theme.MapToolsTheme
import hos.location.LocationData
import hos.map.coordinate.CoordinateType
import hos.map.coordinate.LatLng
import hos.map.coordinate.LatLngBounds
import hos.map.coordinate.LatLngCollection
import hos.map.geometry.Circle
import hos.map.geometry.Polygon

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MapToolsTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting("Android")
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    val latLngCollection = LatLngCollection(CoordinateType.wgs84)
    latLngCollection.add(38.365487, 116.2354686)
    latLngCollection.add(37.365487, 116.2554686)
    latLngCollection.add(38.865487, 116.2754686)
    latLngCollection.add(37.655487, 116.2154686)
    latLngCollection.add(37.311487, 116.2054686)
    val bounds = LatLngBounds(latLngCollection)
    val polygon = Polygon(latLngCollection)
    val circle = Circle(LatLng(38.865487, 116.2754686, CoordinateType.wgs84), 35)
    Log.d("TAG", latLngCollection.toJson())
    Log.d("TAG", polygon.toJson())
    Log.d("TAG", circle.toJson())
    Log.d("TAG", bounds.toJson())
    val locationData = LocationData.Builder(CoordinateType.wgs84)
        .latitude(37.311487)
        .longitude(116.2054686)
        .satellitesNum(5)
        .accuracy(15f)
        .altitude(16.2)
        .speed(56f)
        .direction(45f)
        .time(System.currentTimeMillis())
        .build()
    Log.d("TAG", locationData.toJson())
    Log.d("TAG", locationData.latLng.toJsonAll())
    LazyColumn {
        item {
            Text(text = "LatLngCollection:${latLngCollection.toJson()}")
        }
        item {
            Text(text = "Polygon:${polygon.toJson()}")
        }
        item {
            Text(text = "Circle:${circle.toJson()}")
        }
        item {
            Text(text = "LatLngBounds:${bounds.toJson()}")
        }
        item {
            Text(text = "Holle:$name")
        }
    }
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    MapToolsTheme {
        Greeting("Android")
    }
}